package mz.matafe.bolao

import mz.matafe.bolao.*
import mz.matafe.bolao.exception.*

class RoleService {

    boolean transactional = true

    def delete(roleId) {
        Role role = Role.get(roleId)
        if (role){
            if (!role.users.isEmpty()){
                throw new ServiceException(messageKey: 'role.has.users', args:[role.code])
            }
            return role.delete(flush: true)
        }else{
            throw new ServiceException(messageKey: 'default.not.found.message', args:[${roleId}])
        }
    }
}
